//
//  XQCameraSettingView.m
//  XQBluetooth
//
//  Created by 包月兴 on 16/6/19.
//  Copyright © 2016年 包月兴. All rights reserved.
//

#import "XQCameraSettingView.h"

@interface XQCameraSettingView()
@property (nonatomic,copy) UILabel *countTitleLabel;
@property (nonatomic,copy) UILabel *intervalTitleLabel;
@property (nonatomic,copy) UIButton *countThreeBtn;
@property (nonatomic,copy) UIButton *countFiveBtn;
@property (nonatomic,copy) UIButton *countTenBtn;
@property (nonatomic,copy) UIButton *intervalTwoBtn;
@property (nonatomic,copy) UIButton *intervalThreeBtn;
@property (nonatomic,copy) UIButton *intervalFourBtn;
@end
@implementation XQCameraSettingView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _countTitleLabel = self.countTitleLabel;
        _countThreeBtn = self.countThreeBtn;
        _countFiveBtn = self.countFiveBtn;
        _countTenBtn = self.countTenBtn;
        _intervalTitleLabel = self.intervalTitleLabel;
        _intervalTwoBtn = self.intervalTwoBtn;
        _intervalThreeBtn = self.intervalThreeBtn;
        _intervalFourBtn = self.intervalFourBtn;
    }
    return self;
}


-(UILabel *)countTitleLabel
{
    if (_countTitleLabel == nil) {
        _countTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10,195, 20)];
        _countTitleLabel.font = [UIFont boldSystemFontOfSize:15];
        _countTitleLabel.textColor = [UIColor darkGrayColor];
        _countTitleLabel.text = @"连拍次数";
        [self addSubview:_countTitleLabel];
    }
    return _countTitleLabel;
}


-(UILabel *)intervalTitleLabel
{
    if (_intervalTitleLabel == nil) {
        _intervalTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,100,195, 20)];
        _intervalTitleLabel.font = [UIFont boldSystemFontOfSize:15];
        _intervalTitleLabel.textColor = [UIColor darkGrayColor];
        _intervalTitleLabel.text = @"连拍间隔";
        [self addSubview:_intervalTitleLabel];
        
    }
    return _intervalTitleLabel;
}


-(UIButton *)countThreeBtn
{
    if (_countThreeBtn == nil) {
        _countThreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _countThreeBtn.frame = CGRectMake(10,40,90,35);
        _countThreeBtn.tag = 10;
        [_countThreeBtn setTitle:@"3" forState:UIControlStateNormal];
        [_countThreeBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_countThreeBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg"] forState:UIControlStateNormal];
        [_countThreeBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg_press"] forState:UIControlStateSelected];
        [_countThreeBtn addTarget:self action:@selector(countBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_countThreeBtn];
    }
    return _countThreeBtn;
}

-(UIButton *)countFiveBtn
{
    if (_countFiveBtn == nil) {
        _countFiveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _countFiveBtn.frame = CGRectMake(115,40,90,35);
        _countFiveBtn.tag = 20;
        [_countFiveBtn setTitle:@"5" forState:UIControlStateNormal];
        [_countFiveBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_countFiveBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg"] forState:UIControlStateNormal];
        [_countFiveBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg_press"] forState:UIControlStateSelected];
        [_countFiveBtn addTarget:self action:@selector(countBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_countFiveBtn];
        
    }
    return _countFiveBtn;
}

-(UIButton *)countTenBtn
{
    if (_countTenBtn == nil) {
        _countTenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _countTenBtn.frame = CGRectMake(220,40,90,35);
        _countTenBtn.tag = 30;
        [_countTenBtn setTitle:@"10" forState:UIControlStateNormal];
        [_countTenBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_countTenBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg"] forState:UIControlStateNormal];
        [_countTenBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg_press"] forState:UIControlStateSelected];
        [_countTenBtn addTarget:self action:@selector(countBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_countTenBtn];
        
    }
    return _countTenBtn;
}

-(UIButton *)intervalTwoBtn
{
    if (_intervalTwoBtn == nil) {
        _intervalTwoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _intervalTwoBtn.frame = CGRectMake(10,130,90,35);
        _intervalTwoBtn.tag = 40;
        [_intervalTwoBtn setTitle:@"2s" forState:UIControlStateNormal];
        [_intervalTwoBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_intervalTwoBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg"] forState:UIControlStateNormal];
        [_intervalTwoBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg_press"] forState:UIControlStateSelected];
        [_intervalTwoBtn addTarget:self action:@selector(intervalBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_intervalTwoBtn];
    }
    return _intervalTwoBtn;
}

-(UIButton *)intervalThreeBtn
{
    if (_intervalThreeBtn == nil) {
        _intervalThreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _intervalThreeBtn.frame = CGRectMake(115,130,90,35);
        _intervalThreeBtn.tag = 50;
        [_intervalThreeBtn setTitle:@"3s" forState:UIControlStateNormal];
        [_intervalThreeBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_intervalThreeBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg"] forState:UIControlStateNormal];
        [_intervalThreeBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg_press"] forState:UIControlStateSelected];
        [_intervalThreeBtn addTarget:self action:@selector(intervalBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_intervalThreeBtn];
    }
    return _intervalThreeBtn;
}

-(UIButton *)intervalFourBtn
{
    if (_intervalFourBtn == nil) {
        _intervalFourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _intervalFourBtn.frame = CGRectMake(220,130,90,35);
        _intervalFourBtn.tag = 60;
        [_intervalFourBtn setTitle:@"4s" forState:UIControlStateNormal];
        [_intervalFourBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_intervalFourBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg"] forState:UIControlStateNormal];
        [_intervalFourBtn setBackgroundImage:[UIImage imageNamed:@"camera_setting_bg_press"] forState:UIControlStateSelected];
        [_intervalFourBtn addTarget:self action:@selector(intervalBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_intervalFourBtn];
    }
    return _intervalFourBtn;
}


-(void)countBtnClick:(UIButton *)sender
{
    sender.selected = !sender.selected;
    switch (sender.tag) {
        case 10:
        {
            if (sender.selected) {
                self.countFiveBtn.selected = NO;
                self.countTenBtn.selected = NO;
                if (_cameraCountBlock) {
                    _cameraCountBlock(3);
                }
            }else
            {
                if (_cameraCountBlock) {
                    _cameraCountBlock(0);
                }
            }
        }
            break;
        case 20:
        {
            if (sender.selected) {
                self.countThreeBtn.selected = NO;
                self.countTenBtn.selected = NO;
                if (_cameraCountBlock) {
                    _cameraCountBlock(5);
                }
            }else
            {
                if (_cameraCountBlock) {
                    _cameraCountBlock(0);
                }
            }
        }
            break;
        case 30:
        {
            if (sender.selected) {
                self.countThreeBtn.selected = NO;
                self.countFiveBtn.selected = NO;
                if (_cameraCountBlock) {
                    _cameraCountBlock(10);
                }
            }else
            {
                if (_cameraCountBlock) {
                    _cameraCountBlock(0);
                }
            }
        }
            break;
            
        default:
            break;
    }
    
}
-(void)intervalBtnClick:(UIButton *)sender
{
    sender.selected = !sender.selected;
    switch (sender.tag) {
        case 40:
        {
            if (sender.selected) {
                self.intervalThreeBtn.selected = NO;
                self.intervalFourBtn.selected = NO;
                if (_cameraIntervalBlock) {
                    _cameraIntervalBlock(2);
                }
                
            }else
            {
                if (_cameraIntervalBlock) {
                    _cameraIntervalBlock(0);
                }
            }
        }
            break;
        case 50:
        {
            if (sender.selected) {
                self.intervalTwoBtn.selected = NO;
                self.intervalFourBtn.selected = NO;
                if (_cameraIntervalBlock) {
                    _cameraIntervalBlock(3);
                }
                
            }else
            {
                if (_cameraIntervalBlock) {
                    _cameraIntervalBlock(0);
                }
            }
        }
            break;
        case 60:
        {
            if (sender.selected) {
                self.intervalTwoBtn.selected = NO;
                self.intervalThreeBtn.selected = NO;
                if (_cameraIntervalBlock) {
                    _cameraIntervalBlock(4);
                }
                
            }else
            {
                if (_cameraIntervalBlock) {
                    _cameraIntervalBlock(0);
                }
            }
        }
            break;

            
        default:
            break;
    }
}

@end
